import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.Random;
import Card.card;
import com.sun.jarsigner.ContentSignerParameters;

class MyArray<T> {
//    public  T[] obj = (T[])new Object[10];
//    public  Object[] obj = new Object[10];
    public  T[] obj = (T[]) new Object[10];
    public MyArray() {

    }

    public void setVal(int pos,T val) {
        obj[pos] = val;
    }

    public T getPos(int pos) {
        return (T)obj[pos];
    }
}

public class Test {
    public static final String[] SUITS = {"♠","♥","♣","♦"};
    private static List<card> buyDeck() {
        List<card> deck = new ArrayList<>(52);
        for (int i = 0; i < 4; ++i) {
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                int rank = j;
                card card1 = new card();
                card1.rank = rank;
                card1.suit = suit;
                deck.add(card1);
            }
        }
        return deck;
    }
    private static void swap(List<card> deck,int i,int j) {
        card t = deck.get(i);
        deck.set(i,deck.get(j));

        deck.set(j,t);
    }

    private static void shuffie(List<card> deck) {
        Random random = new Random(20250305);
        for(int i = deck.size() - 1; i > 0; i--) {
            int r = random.nextInt(i);
            swap(deck,i,r);
        }
    }
    public static void main(String[] args) {
        List<card> deck = buyDeck();
        System.out.println("刚买回来的牌");
        System.out.println(deck);
        System.out.println(deck.size());

        shuffie(deck);
        System.out.println("洗过的牌");
        System.out.println(deck);
        System.out.println(deck.size());


        List<List<card>> hands = new ArrayList<>();
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());

        for(int i =0; i<5; i++) {
            for(int j =0; j<3; j++) {
                hands.get(j).add(deck.remove(0));
            }
        }

        System.out.println("剩余的牌");
        System.out.println(deck);
        System.out.println(deck.size());
        System.out.println("A手中的牌");
        System.out.println(hands.get(0));
        System.out.println("B手中的牌");
        System.out.println(hands.get(1));
        System.out.println("C手中的牌");
        System.out.println(hands.get(2));
    }

    public static void main7(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        for(Integer e : list) {
            System.out.println(e);
        }

        System.out.println();

        // lis.iterator() 遍历方向只能往后遍历，支持remove（）
        // list.listIterator() 遍历方向是双向的，支持remove()  add() set()

        Iterator<Integer> it = list.listIterator();
        while(it.hasNext()) {
            System.out.println(it.next() + " ");
        }


    }
    public static void main6(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("JavaSE");
        list.add("JavaWeb");
        list.add("JavaEE");
        list.add("JVM");
        list.add("测试课程");
        list.add(1,"java数据结构");
        System.out.println(list);

        // 删除指定元素，找到了就删除，然后将后面的元素全部往前面移动
        list.remove("JVM");
        System.out.println(list);

        list.remove(list.size() - 1);
        System.out.println(list);

        if(list.contains("测试课程")) {
            list.add("测试课程");
        }

        // indexOf是从前开始找，lastIndexOf是从后开始找
        System.out.println(list.indexOf("JavaSE"));
        System.out.println(list.lastIndexOf("JavaSE1"));

        list.add("1");
        list.add("2");
        list.add("3");
        System.out.println(list);

        // 使用list中[0,4]之间的元素构成的一个新的sublist 和list是共用的一个elementData数组
        List<String> ret = list.subList(0,4);
        System.out.println(ret);

        list.clear();
        System.out.println(list.size());
    }

    public static void main5(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("JavaSE");
        list.add("JavaWeb");
        list.add("JavaEE");
        list.add("JVM");
        list.add("测试课程");

        System.out.println(list);

        System.out.println(list.size());
        System.out.println(list.get(1));
        list.set(1,"JavaWeb2");
        System.out.println(list.get(1));
//        System.out.println(list.get(5));


        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);

        System.out.println(list1);
    }
    public static void main4(String[] args) {
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);

        for(Integer e : list1) {
            System.out.println(e);
        }

        // 这种情况就可以，因为忽略类型，可以放任何类型，但是使用的时候是一场灾难
        List list2 = new ArrayList();
        list2.add("111");
        list2.add(100);

        for(Object e : list2) {
            System.out.println(e);
        }

    }
    public static void main3(String[] args) {
        MyArray myArray = new MyArray();
        myArray.setVal(0,10);
        myArray.setVal(1,"hello");
        String ret = (String)myArray.getPos(1);

        System.out.println(ret);
    }
    public static void main2(String[] args) {
        MyArray<Integer> myArray = new MyArray<Integer>();
        myArray.setVal(0,10);
        myArray.setVal(1,2);
        myArray.setVal(2,6);

        int a = myArray.getPos(1);
        MyArray<String> myArray1 = new MyArray<String>();
        myArray1.setVal(0,"hello");
        myArray1.setVal(1,"world");
        String str = myArray1.getPos(0);

        System.out.println(str);
        System.out.println(myArray1.getPos(1));
    }
    public static void main1(String[] args) {
        // Interger 底层有一个缓存数组，如果数据在-128 - 127 那么就映射在缓存数组上
        // 如果不是的话，就会new一个
        Integer a = 127;
        Integer b = 127;

        Integer c = 128;
        Integer d = 128;

        System.out.println(a == b);
        System.out.println(c == d);
    }
}
